#!/bin/bash
###
 # @Author: dvlproad
 # @Date: 2023-04-29 15:23:47
 # @LastEditors: dvlproad
 # @LastEditTime: 2023-06-09 13:50:09
 # @Description: 
### 
#source a_source_env.sh -appInfoF ${ENVIRONMENT_FILE_PATH}
#source a_source_env.sh -appInfoF "app_info.json"

# 定义颜色常量
NC='\033[0m' # No Color
RED='\033[31m'
GREEN='\033[32m'
YELLOW='\033[33m'
BLUE='\033[34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'

# shell 参数具名化
show_usage="args: [-appInfoF]\
                                  [--app-info-json-file=]"

while [ -n "$1" ]
do
        case "$1" in
                -appInfoF|--app-info-json-file) ENVIRONMENT_FILE_PATH=$2; shift 2;;
                --) break ;;
                *) echo $1,$2,$show_usage; break ;;
        esac
done

if [ ! -f "${ENVIRONMENT_FILE_PATH}" ];then
    echo "$0 ❌:您的${ENVIRONMENT_FILE_PATH}文件不存在，请检查！"
    exit_script
fi


JQ_EXEC=`which jq`

BRANCH=$(cat $ENVIRONMENT_FILE_PATH | ${JQ_EXEC} .package_from_brance | sed 's/\"//g')
# 检查字符串是否包含空格
if [[ $BRANCH =~ [[:space:]] ]]; then
        printf "${PURPLE}温馨提示：从 ${ENVIRONMENT_FILE_PATH} 中的 package_from_brance 获取到的分支名 ${BRANCH} 含有空格，不正确，这里为保证后续路径或文件名等正常，临时帮你去掉分支中的空格。${NC}\n"
        # 字符串中包含空格，使用 tr 命令删除空格
        BRANCH=$(echo $BRANCH | tr -d ' ')
fi

PlatformType=$(cat $ENVIRONMENT_FILE_PATH | ${JQ_EXEC} .platform_type | sed 's/\"//g')
PackageTargetType=$(cat $ENVIRONMENT_FILE_PATH | ${JQ_EXEC} .package_default_target | sed 's/\"//g')
PackageNetworkType=$(cat $ENVIRONMENT_FILE_PATH | ${JQ_EXEC} .package_default_env | sed 's/\"//g')
#echo "BRANCH=$BRANCH,PlatformType=$PlatformType,PackageTargetType=$PackageTargetType,PackageTargetType=$PackageTargetType"
